package com.demo.rydemo.d_role_res.service.impl;

import com.demo.rydemo.d_role_res.entity.DRoleRes;
import com.demo.rydemo.d_role_res.mapper.DRoleResMapper;
import com.demo.rydemo.d_role_res.service.IDRoleResService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.rydemo.d_role_res.vo.DRoleResVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ry
 * @since 2020-08-27
 */
@Service
public class DRoleResServiceImpl extends ServiceImpl<DRoleResMapper, DRoleRes> implements IDRoleResService {

    /**
     * 批量保存角色关联资源
     * @param dRoleResVO
     * @return
     */
    @Override
    public Boolean savesByRoleId(DRoleResVO dRoleResVO) {
        String roleId = dRoleResVO.getRoleId();
        List<DRoleRes> dRoleRess = new ArrayList<>();
        for (int i = 0; i < dRoleResVO.getRess().length; i++) {
            DRoleRes dRoleRes = new DRoleRes();
            dRoleRes.setRoleResId(UUID.randomUUID().toString().replace("-",""))
            .setCreateTime(new Date()).setResId(dRoleResVO.getRess()[i]).setRoleId(roleId);
            dRoleRess.add(dRoleRes);
        }

        return saveBatch(dRoleRess);
    }
}
